home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / Oberon⁄F™ 1.1 / Obx / Docu / MMerge (.txt) < prev    next >
Encoding:
Oberon Document  |  1996-01-05  |  7.4 KB  |  94 lines  |  [oODC/obnF]

  1. Documents.StdDocumentDesc
  2. Documents.DocumentDesc
  3. Containers.ViewDesc
  4. Views.ViewDesc
  5. Stores.StoreDesc
  6. Documents.ModelDesc
  7. Containers.ModelDesc
  8. Models.ModelDesc
  9. Stores.ElemDesc
  10. TextViews.StdViewDesc
  11. TextViews.ViewDesc
  12. TextModels.StdModelDesc
  13. TextModels.ModelDesc
  14. TextModels.AttributesDesc
  15. Helvetica
  16. TextRulers.StdRulerDesc
  17. TextRulers.RulerDesc
  18. TextRulers.StdStyleDesc
  19. TextRulers.StyleDesc
  20. TextRulers.AttributesDesc
  21. Helvetica
  22. Helvetica
  23. HostPictures.StdViewDesc
  24.     Helvetica
  25. address database
  26. letter template
  27. x     address
  28. Jim   Long Street 1
  29. Joe   First Ave. 39
  30. Moe  Terrace Blvd.
  31. address
  32. Dear <
  33. we wanted to
  34. notify you of
  35. our new
  36. product...
  37. mail merge
  38. Long Street 1
  39. Dear Jim,
  40. we wanted to
  41. notify you of
  42. our new
  43. product...
  44. form letters
  45. StdLinks.LinkDesc
  46. StdCmds.OpenDoc('Obx/Samples/mmTmpl')
  47. Helvetica
  48. StdCmds.OpenDoc('Obx/Samples/mmData')
  49. Helvetica
  50. Helvetica
  51. MODULE ObxMailMerge;
  52.     PROCEDURE TmplFields (t: TextModels.Model): Field;
  53.     PROCEDURE ThisDatabase (): TextModels.Model;
  54.     PROCEDURE MergeFields (f: Field; t: TextModels.Model);
  55.     PROCEDURE ReadTuple (f: Field; r: TextModels.Reader);
  56.     PROCEDURE AppendInstance (f: Field; data, tmpl, out: TextModels.Model);
  57.     PROCEDURE Merge*;
  58. END ObxMailMerge.
  59. TextControllers.StdCtrlDesc
  60. TextControllers.ControllerDesc
  61. Containers.ControllerDesc
  62. Controllers.ControllerDesc
  63. Helvetica
  64. StdCmds.OpenDoc('Obx/Mod/MMerge')
  65. Oberon by Example: ObxMailMerge
  66. When a business wants to communicate something to all its customers, e.g. the announcement of a new product, it can send out form letters to all its existing customers. Each such letter has the same contents, except for a few differences like the name and address of the respective customer. Mail merge is the process of creating these form letters out of a letter template and a customer database.
  67. This example shows how Oberon/F's built-in text facilities can be used to implement a simple mail merge extension.
  68. Mail Merge Process
  69. To try out ObxMMerge, compile it, install the following command in some menu:
  70.     "Merge"    ""    "ObxMMerge.Merge"    "TextCmds.FocusGuard"
  71. then open the mail merge 
  72. template
  73. document
  74.  (mmTmpl) in the Obx/Samples directory and then execute the Merge command. A dialog box will ask you for the address database; open the mail merge 
  75. document
  76.  (mmData) in the Obx/Samples directory.
  77. As a result, a new text is created which contains a sequence of form letters. When you execute the Show
  78. Marks command in the Text menu, you'll note that the individual letters are separated by page-breaking rulers.
  79. Now let's take a closer look at how the program is implemented. There is one command called Merge, which gets the template text (the focus), searches for place holders in this text (the fields of the template), then lets the user open the database text, determines for each template field which column of the database text corresponds to the field, creates a new output text, adds an instance of the letter template for every row of the database text, and finally opens the text in a window.
  80.     Outline of the ObxMMerge Program:
  81. There are five auxiliary procedures which are called by Merge:
  82. TmplFields analyzes the template text, and returns a list of fields for this text. Each field describes a place holder with its name and its position in the text. Place holders are specified as names between "<" and ">" characters, e.g. <Name>.
  83. ThisDatabase asks the user for a database document, and returns the text contained in this document.
  84. MergeFields determines for every template field the corresponding database column. To make this possible, the first row of the database text must contain the so-called meta data of the database. For mail merge applications, this is simply the symbolic name of every column, e.g. Name or City. This name must be identical to the name used in the template.
  85. Each row is terminated by a carriage return (0DX), and the fields of a row (the columns) are separated by tabs (09X).
  86. ReadTuple reads one row of the database text, and assigns the text range occupied by one database field to every corresponding template field.
  87. AppendInstance appends a copy of the template text to the end of the output text, and then replaces all the place holders by the contents of their respective database fields. These replacements are done from the end of the appended text towards the beginning, so that from/to indices are not invalidated by replacements. This explains why the field list is built up in reverse order, last field first.
  88. Note that each replacement gets the text attributes of the first replaced character, i.e. if the place holder "<Name>" in bold face is replaced by the string "Joe", the resulting replacement will be 'Joe".
  89. ObxMMerge doesn't insert page-breaking rulers of its own; instead, the template text contains such a ruler.
  90. ObxMMerge
  91. sources
  92. Helvetica
  93. Documents.ControllerDesc
  94.